/**
 * 
 */
package com.info.dpunified.web.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.info.dpunified.common.utils.DPUUnifiedConstants;
import com.info.dpunified.defects.DefectsSelector;

/**
 * @author varun
 *
 */
public class DefectFilterServlet extends HttpServlet implements DPUUnifiedConstants{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public void doGet(HttpServletRequest request,  
            HttpServletResponse response) throws IOException,  
                                                 ServletException {  
		doPost(request, response);  
	}  

	public void doPost(HttpServletRequest request,HttpServletResponse response)
	throws ServletException, IOException
	{
		
		DefectsSelector defectsSelector = new DefectsSelector();
		defectsSelector.populateFilterCriteria();
		
		HashMap<String, ArrayList<String>> filterCriteria = defectsSelector.getFilterCriteriaMap();
		
		request.setAttribute(YEAR, filterCriteria.get(YEAR));
		request.setAttribute(MONTH, filterCriteria.get(MONTH));
		request.setAttribute(PROJECTCODE, filterCriteria.get(PROJECTCODE));
		request.setAttribute(DEFECTIMPACT, filterCriteria.get(DEFECTIMPACT));
		request.setAttribute(DEFECTPRIORITY, filterCriteria.get(DEFECTPRIORITY));
		request.setAttribute(DEFECTSEVERITY, filterCriteria.get(DEFECTSEVERITY));
		request.setAttribute(DEFECTSTATUS, filterCriteria.get(DEFECTSTATUS));
		request.setAttribute(DEFECTTYPE, filterCriteria.get(DEFECTTYPE));
		
		if(filterCriteria == null || filterCriteria.isEmpty())
		{
			request.setAttribute("defects", "notfound");
			request.setAttribute("defectsnotfound", "No defects submitted");
		}
		
		try {
			getServletConfig().getServletContext().getRequestDispatcher("/jsp/viewdefects.jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	
}
